package com.zsh.wanandroid.ui.adapter;

import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.zsh.wanandroid.R;
import com.zsh.wanandroid.bean.ArticleBean;
import com.zsh.wanandroid.bean.ArticleTags;
import com.zsh.wanandroid.bean.ProjectBean;
import com.zsh.wanandroid.bean.ProjectTagsBean;

import java.util.List;

/**
 * @author zsh
 * @date 2020/3/19.
 * 功能：项目adapter
 */

public class ProjectAdapter extends BaseQuickAdapter<ArticleBean<ArticleTags>, BaseViewHolder> {



    public ProjectAdapter(@LayoutRes int layoutResId, @Nullable List<ArticleBean<ArticleTags>> data) {
        super(layoutResId, data);
    }

    public ProjectAdapter(@LayoutRes int layoutResId) {
        super(layoutResId);
    }

    public ProjectAdapter(@Nullable List<ArticleBean<ArticleTags>> data) {
        super(data);
    }

    @Override
    protected void convert(BaseViewHolder helper, ArticleBean<ArticleTags> item) {
        //图片，是否为项目
        if (!item.getEnvelopePic().equals("")) {
            helper.setVisible(R.id.ivPic, true);
            Glide.with(mContext).load(item.getEnvelopePic()).error(R.drawable.default_pic)
                    .placeholder(R.drawable.default_pic)
                    .into((ImageView) helper.getView(R.id.ivPic));
        }
        //标题
        helper.setText(R.id.tvTitle, item.getTitle());
        //内容
        helper.setText(R.id.tvContent, item.getDesc().replace("\r\n", ""));
        //作者
        String author = item.getAuthor();
        String shareUser = item.getShareUser();
        helper.setText(R.id.tvShareUser, !author.equals("") ? author : shareUser);
        //时间
        helper.setText(R.id.tvTime, item.getNiceDate());
        //是否收藏
        if (item.isCollect()) {
            helper.setBackgroundRes(R.id.ivLike, R.drawable.ic_like);
        } else {
            helper.setBackgroundRes(R.id.ivLike, R.drawable.ic_like_not);
        }
    }
}
